package com.leon.alishop.core.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import com.leon.alishop.model.AttrInfo;
import com.leon.alishop.model.AttrValInfo;

public class AttributesModel extends AttrInfo{

	private Vector<AttrValInfo> attrValList;

	public Vector<AttrValInfo> getAttrValList() {
		return attrValList;
	}

	public void setAttrValList(Vector<AttrValInfo> attrValList) {
		this.attrValList = attrValList;
	}
	
	public boolean addAttrVal(AttrValInfo attrVal) {
		if(null == attrValList)
			attrValList = new Vector<AttrValInfo>();
		return attrValList.add(attrVal);
	}
	
	public boolean addAttrValList(List<AttrValInfo> attrValList) {
		if(null == attrValList)
			attrValList = new ArrayList<AttrValInfo>();
		return attrValList.addAll(attrValList);
	}
	
	public AttrInfo getAttrInfo(){
		return (AttrInfo)this;
	}
	
	public AttrValInfo getAttrValInfo(String name){
		if(null == name
				|| name.length()==0)
				return null;
		List<AttrValInfo> attrVals = new ArrayList<AttrValInfo>(attrValList);
		if(null == attrVals
				|| attrVals.size()==0)
			return null;
		for (AttrValInfo avi : attrVals) {
			if(avi.getValueName().equals(name))
				return avi;
		}
		return null;
	}
	
	public AttrValInfo getAttrValInfo(Integer id){
		if(null == id)
				return null;
		List<AttrValInfo> attrVals = new ArrayList<AttrValInfo>(attrValList);
		if(null == attrVals
				|| attrVals.size()==0)
			return null;
		for (AttrValInfo avi : attrVals) {
			if(id.equals(avi.getId()))
				return avi;
		}
		return null;
	}
	
}
